﻿using System;
using System.Web.Mvc;
using cludg.Web.Core.Controllers;
using cludg.Domain.Content;

namespace cludg.Web.Core.RenderHelpers
{
	public static class PermissionHelper
	{
		public static bool HasPermission(this HtmlHelper html, string permissionName, IContent content = null)
		{
			var controller = html.ViewContext.Controller as BaseController;
			if (controller == null)
			{
				throw new ApplicationException("HasPermission helper can be user only with BaseController objects.");
			}

			return controller.CurrentUserHasPermission(permissionName, content);
		}
	}
}
